package com.itcast.demo_one

import android.os.Bundle
import android.widget.SimpleAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class CityIconActivity : AppCompatActivity() {

    // 数据类
    data class CityData(val name: String, val icon: Int)
    // 1. 定义城市列表
     val cityList = listOf(
        CityData("北京",R.drawable.bj ),
        CityData("上海",R.drawable.sh ),
        CityData("广州",R.drawable.gz ),
        CityData("深圳",R.drawable.sz ),
        CityData("杭州",R.drawable.hz ),
        CityData("南京",R.drawable.nj ),
    )
    private lateinit var spinner: Spinner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_city_icon)

        // 1.获取下拉框组件
        spinner = findViewById(R.id.spinner_icon)

        // 2.创建适配器
        val adapter = SimpleAdapter(
            this,
            cityList.map {
                mapOf("name" to it.name, "icon" to it.icon)
            },
            R.layout.item_icon,
            arrayOf("name", "icon"),
            intArrayOf(R.id.text, R.id.icon)
        )

        // 3.设置适配器
        spinner.adapter = adapter
    }
}